/*
 * SvrConfig.h
 *
 *  Created on: 2012-7-11
 *      Author: ThinkPad
 */

#ifndef SVRCONFIG_H_
#define SVRCONFIG_H_

#include "utils.h"

/*
*svr status
*/
enum Server_Status
{
	SV_NONE = 0,
	SV_INIT = 1,
	SV_HEARTBEAT = 2,
	SV_CLOSE = 3
};

enum Heartbeat_STATUS
{
	HT_CLOSE,
	HT_RUN
};

/*
 * Server config class
 */
class SvrConfig
{
public:
  SvrConfig();
  ~SvrConfig();

  int init();
  int update();
  bool set_authsvr_address();
  size_t get_root_path_len();

  bool set_cdnsvr_address();
  uint32_t struct_heartbeat_data(char * buf,size_t buf_len);
  int handle_heartbeat_data(char * buf,size_t buf_len);

  int  listen_port;
  char listen_ip[32];

  char log_path[FILE_MAX_PATH];
  int  loglevel;

  char rootpath[FILE_MAX_PATH];
  char virtualpath[FILE_MAX_PATH];

  char pidfilepath[FILE_MAX_PATH];

  char Svr_Name[128];
  int  Svr_Id;

  bool is_net_auth;
  char auth_host[FILE_MAX_PATH];
  char auth_ip[32];
  int  auth_port;

  char cdn_host[FILE_MAX_PATH];
  char cdn_ip[32];
  int  cdn_port;

  char dbpath[FILE_MAX_PATH];
  char limit_ip[32];
  char svr_key[128];
  char listenethname[16];

  int  clearOutTime;

  int svr_max_connect_count;
  int svr_handle_threads;

  Server_Status svrStatus;
  Heartbeat_STATUS htStatus;

protected:
  void init_config_path(void);
  int SavePid();

private:
  char  configpath[FILE_MAX_PATH];
  char  config_file[FILE_MAX_PATH];
  char  str_buf[FILE_MAX_PATH];
  size_t rootpath_len;
};

#endif /* SVRCONFIG_H_ */
